/* Copyright.

 */

function login(){
    if(!valid()){
        return;
    }
    var name = $("#username").val();
    var pswd = $("#password").val();
    var username = DesUtils.encode(name, "hcst");
    var password = DesUtils.encode(pswd, "hcst");
    alert("username："+username)
    alert("password"+password)
    var url = baseUrl+"login?__login=true&__ajax=json&username="+username+"&password="+password+"&validCode=&__sid=";
    console.log(url);
    $.ajax({
        url:url,
        type:"get",
        contentType:"application/json;charset=utf-8",
        success: function (result) {
            // alert(JSON.stringify(result));
            if(result.result=="false"){
                alert(result.message);
                return;
            }
            $api.setStorage("username",username);
            $api.setStorage("password",password);
            $api.setStorage("sessionid",result.sessionid);
            $api.setStorage("user",result.user);
            toView("news.html");
            alert(result.message);
        },
        error: function (e) {
            alert(JSON.stringify(e));
        },
        complete: function () {
            
        }
    });
}


function valid(){
    var username = $("#username").val();
    var password = $("#password").val();
    if(username==""||username==undefined){
        alert("用户名为空！");
        return false;
    }
    if(password==""||password==undefined){
        alert("密码为空！");
        return false;
    }
    return true;
}

